home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FFT / FFTR2CC.ASM < prev    next >
Assembly Source File  |  1990-01-17  |  7KB  |  161 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Radix 2, In-Place, Decimation-In-Time FFT (fast).
  6. ; Last Update 18-Aug-88   Version 1.0
  7. ;
  8. fftr2cc  macro   points,data,coef
  9. fftr2cc  ident   1,0
  10. ;
  11. ; Radix 2 Decimation in Time In-Place Fast Fourier Transform Routine
  12. ;
  13. ;    Complex input and output data
  14. ;        Real data in X memory
  15. ;        Imaginary data in Y memory
  16. ;    Normally ordered input data
  17. ;    Bit reversed output data
  18. ;       Coefficient lookup table
  19. ;        -Cosine values in X memory
  20. ;        -Sine values in Y memory
  21. ;
  22. ; Macro Call - fftr2cc   points,data,coef
  23. ;
  24. ;       points     number of points (16-32768, power of 2)
  25. ;       data       start of data buffer
  26. ;       coef       start of sine/cosine table
  27. ;
  28. ; Alters Data ALU Registers
  29. ;       x1      x0      y1      y0
  30. ;       a2      a1      a0      a
  31. ;       b2      b1      b0      b
  32. ;
  33. ; Alters Address Registers
  34. ;       r0      n0      m0
  35. ;       r1      n1      m1
  36. ;               n2
  37. ;
  38. ;       r4      n4      m4
  39. ;       r5      n5      m5
  40. ;       r6      n6      m6
  41. ;
  42. ; Alters Program Control Registers
  43. ;       pc      sr
  44. ;
  45. ; Uses 6 locations on System Stack
  46. ;
  47. ; Latest Revision -  18-Aug-88
  48. ;
  49.      move #data,r0            ;initialize input pointer
  50.      move #points/4,n0        ;initialize input and output pointers offset
  51.      move n0,n4               ;
  52.      move n0,n6               ;initialize coefficient offset
  53.      move #points-1,m0        ;initialize address modifiers
  54.      move m0,m1               ;for modulo addressing
  55.      move m0,m4
  56.      move m0,m5
  57. ;
  58. ; Do first and second Radix 2 FFT passes, combined as 4-point butterflies
  59. ;
  60.      move           x:(r0)+n0,x0
  61.      tfr  x0,a      x:(r0)+n0,y1   
  62.  
  63.      do   n0,_twopass
  64.      tfr  y1,b      x:(r0)+n0,y0
  65.      add  y0,a      x:(r0),x1                     ;ar+cr
  66.      add  x1,b      r0,r4                         ;br+dr
  67.      add  a,b       (r0)+n0                       ;ar'=(ar+cr)+(br+dr)
  68.      subl b,a       b,x:(r0)+n0                   ;br'=(ar+cr)-(br+dr)
  69.      tfr  x0,a      a,x0           y:(r0),b
  70.      sub  y0,a                     y:(r4)+n4,y0   ;ar-cr
  71.      sub  y0,b      x0,x:(r0)                     ;bi-di
  72.      add  a,b                      y:(r0)+n0,x0   ;cr'=(ar-cr)+(bi-di)
  73.      subl b,a       b,x:(r0)                      ;dr'=(ar-cr)-(bi-di)
  74.      tfr  x0,a      a,x0           y:(r4),b
  75.      add  y0,a                     y:(r0)+n0,y0   ;bi+di
  76.      add  y0,b      x0,x:(r0)+n0                  ;ai+ci
  77.      add  b,a                      y:(r0)+,x0     ;ai'=(ai+ci)+(bi+di)
  78.      subl a,b                      a,y:(r4)+n4    ;bi'=(ai+ci)-(bi+di)
  79.      tfr  x0,a                     b,y:(r4)+n4
  80.      sub  y0,a      x1,b                          ;ai-ci
  81.      sub  y1,b      x:(r0)+n0,x0                  ;dr-br
  82.      add  a,b       x:(r0)+n0,y1                  ;ci'=(ai-ci)+(dr-br)
  83.      subl b,a                      b,y:(r4)+n4    ;di'=(ai-ci)-(dr-br)
  84.      tfr  x0,a                     a,y:(r4)+
  85. _twopass
  86. ;
  87. ; Perform all next FFT passes except last pass with triple nested DO loop
  88. ;    
  89.      move #points/8,n1        ;initialize butterflies per group
  90.      move #4,n2               ;initialize groups per pass
  91.      move #-1,m2              ;linear addressing for r2
  92.      move #0,m6               ;initialize C address modifier for
  93.                               ;reverse carry (bit-reversed) addressing
  94.  
  95.      do   #@cvi(@log(points)/@log(2)-2.5),_end_pass    ;example: 7 passes for 1024 pt. FFT
  96.      move #data,r0                                     ;initialize A input pointer
  97.      move r0,r1
  98.      move n1,r2
  99.      move r0,r4                                        ;initialize A output pointer
  100.      move (r1)+n1                                      ;initialize B input pointer
  101.      move r1,r5                                        ;initialize B output pointer
  102.      move #coef,r6                                     ;initialize C input pointer
  103.      lua  (r2)+,n0                                     ;initialize pointer offsets
  104.      move n0,n4
  105.      move n0,n5
  106.      move (r2)-                                        ;butterfly loop count
  107.      move           x:(r1),x1      y:(r6),y0           ;lookup -sine and -cosine values
  108.      move           x:(r6)+n6,x0   y:(r0),b            ;update C pointer, preload data
  109.      mac  x1,y0,b                  y:(r1)+,y1
  110.      macr -x0,y1,b                 y:(r0),a
  111.  
  112.      do   n2,_end_grp
  113.      do   r2,_end_bfy
  114.      subl b,a       x:(r0),b       b,y:(r4)            ;Radix 2 DIT butterfly kernel
  115.      mac  -x1,x0,b  x:(r0)+,a      a,y:(r5)
  116.      macr -y1,y0,b  x:(r1),x1
  117.      subl b,a       b,x:(r4)+      y:(r0),b
  118.      mac  x1,y0,b                  y:(r1)+,y1
  119.      macr -x0,y1,b  a,x:(r5)+      y:(r0),a
  120. _end_bfy
  121.      move (r1)+n1
  122.      subl b,a       x:(r0),b       b,y:(r4)
  123.      mac  -x1,x0,b  x:(r0)+n0,a    a,y:(r5)
  124.      macr -y1,y0,b  x:(r1),x1      y:(r6),y0
  125.      subl b,a       b,x:(r4)+n4    y:(r0),b
  126.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+,y1
  127.      macr -x0,y1,b  a,x:(r5)+n5    y:(r0),a
  128. _end_grp
  129.      move n1,b1
  130.      lsr  b    n2,a1     ;divide butterflies per group by two
  131.      lsl  a    b1,n1     ;multiply groups per pass by two
  132.      move a1,n2
  133. _end_pass
  134. ;
  135. ; Do last FFT pass
  136. ;
  137. ;
  138.         move    #2,n0           ;correct input pointer A offset for last pass
  139.         move    n0,n1           ;correct input pointer B offset for last pass
  140.         move    n0,n4           ;correct output pointer A offset for last pass
  141.         move    n0,n5           ;correct output pointer B offset for last pass
  142.         move    #data,r0        ;initialize A input pointer
  143.         move    r0,r4           ;initialize A output pointer
  144.         lua     (r0)+,r1        ;initialize B input pointer
  145.         move    #coef,r6        ;initialize C input pointer
  146.         lua     (r1)-n1,r5      ;initialize B output pointer
  147.         move    x:(r1),x1       y:(r6),y0
  148.         move    x:(r5),a        y:(r0),b
  149.  
  150.         do      n2,_lastpass    ;Radix 2 DIT butterfly kernel with one
  151.         mac     x1,y0,b x:(r6)+n6,x0    y:(r1)+n1,y1    ;butterfly per group
  152.         macr    -x0,y1,b        a,x:(r5)+n5     y:(r0),a
  153.         subl    b,a     x:(r0),b        b,y:(r4)
  154.         mac     -x1,x0,b        x:(r0)+n0,a     a,y:(r5)
  155.         macr    -y1,y0,b        x:(r1),x1       y:(r6),y0
  156.         subl    b,a             b,x:(r4)+n4     y:(r0),b
  157. _lastpass
  158.         move    a,x:(r5)+n5
  159.         endm^Z